# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=GeographicLib
_pkgname=geographiclib
pkgbase=mingw-w64-${_pkgname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_pkgname}")
pkgver=1.52
pkgrel=2
pkgdesc="Set of C++ classes for conversions between geographic, UTM, UPS, MGRS, geocentric, and local cartesian coordinates, for gravity, geoid height, and geomagnetic field calculations and for solving geodesic problems (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://geographiclib.sourceforge.io/"
license=('custom') # MIT/X11
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen")
options=('!strip' 'staticlibs' '!buildflags')

source=(https://downloads.sourceforge.net/project/geographiclib/distrib/${_realname}-${pkgver}.tar.gz)
sha256sums=('5d4145cd16ebf51a2ff97c9244330a340787d131165cfd150e4b2840c0e8ac2b')

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DCOMMON_INSTALL_PATH=ON \
    -DGEOGRAPHICLIB_DOCUMENTATION=ON \
    -DGEOGRAPHICLIB_LIB_TYPE=BOTH \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  make DESTDIR=${pkgdir} install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_pkgname}/LICENSE"
}
